import 'package:flutter/material.dart';
import 'package:flutter_demo/main.dart';
import 'package:flutter_demo/models/common_model.dart';


class SubNav extends StatelessWidget {

  List<CommonModel> subNavList;

  SubNav({@required this.subNavList});

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: _itemList(context)
      ),
    );
  }

  List<Widget> _itemList(BuildContext context) {
    List<Widget> list = new List();
    subNavList.forEach((value) {
      list.add(_item(context, value));
    });
    int sepe = (list.length / 2 + 0.5).toInt();
    List<Widget> list3 = new List();
    list3.add(Row(children: list.sublist(0, sepe)));
    list3.add(Row(children: list.sublist(sepe, list.length)));
    return list3;
  }




  Widget _item(BuildContext context, CommonModel model) {
    return Expanded(
        flex: 50,
        child: GestureDetector(
          onTap: null,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Container(
                child: Image.network(model.icon, fit: BoxFit.cover, width: 28, height: 28,),
              ),
              Center(child: Text(model.title, style: TextStyle(color: Colors.black87, fontSize: 10),),)
            ],
          ),
      )
    );
  }
}
